package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.Aspect.UserPer;
import com.mc.read.adminapi.manager.LabelManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/14 17:19
 */
@Service
@Slf4j
public class LabelService {
    @Autowired
    LabelManager labelManager;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询标签审核列表 selectLabelAuditList
     **/
    @UserPer(permission = "book:label:selectAuditList")
    @UserLog(operateName = "查询标签审核列表", type = 4)
    public BaseRespose selectLabelAuditList(BaseRequest baseRequest) {
        log.info("查询标签审核列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = labelManager.selectLabelAuditList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询标签审核列表 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询标签审核列表 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 标签审核 不通过 labelAuditNoPass
     **/
    @UserPer(permission = "book:label:auditNoPass")
    @UserLog(operateName = "标签审核 不通过", type = 5)
    public BaseRespose labelAuditNoPass(BaseRequest baseRequest) {
        log.info("标签审核 不通过,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = labelManager.labelAuditNoPass(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("标签审核 不通过 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("标签审核 不通过 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 标签审核 通过 labelAuditPass
     **/
    @UserPer(permission = "book:label:auditPass")
    @UserLog(operateName = "标签审核 通过", type = 5)
    public BaseRespose labelAuditPass(BaseRequest baseRequest) {
        log.info("标签审核 通过,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = labelManager.labelAuditPass(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("标签审核 通过 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("标签审核 通过 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除标签审核记录 deleteLabelAudit
     **/
    @UserPer(permission = "book:label:auditDel")
    @UserLog(operateName = "删除标签审核记录", type = 2)
    public BaseRespose deleteLabelAudit(BaseRequest baseRequest) {
        log.info("删除标签审核记录,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = labelManager.deleteLabelAudit(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("删除标签审核记录 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除标签审核记录 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
}
